<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios AJAX请求</title>
    <script crossorigin="anonymous" src="https://cdn.bootcdn.net/ajax/libs/axios/0.20.0-0/axios.min.js"></script>
</head>

<body>
    <button class="a">GET</button>
    <button class="b">POST</button>
    <button class="c">AJAX请求</button>
    <script>
        var btns = document.querySelectorAll('button');
        btns[0].onclick = function () {
            axios.get('http://127.0.0.1:8000/axios-server', {
                // url参数
                params: {
                    a: 30,
                    b: 90
                },
                // 请求头信息
                headers: {
                    name: 'atguigu',
                    age: 20
                }
            }).then((result) => {
                console.log(result);
            }).catch((err) => {
                console.log('erro');
            });
        };
        btns[1].onclick = function () {
            axios.post('http://127.0.0.1:8000/axios-server', {
                name: 'admin',
                password: 'admin'
            }, {
                // url参数
                params: {
                    a: 30,
                    b: 90
                },
                // 请求头信息
                headers: {
                    name: 'atguigu',
                    age: 20
                }
            }).then((result) => {
                console.log(result);
            }).catch((err) => {
                console.log(err);
            });
        };
        btns[2].addEventListener('click', function () {
            axios({
                method: 'POST',
                url: 'http://127.0.0.1:8000/axios-server',
                params: {
                    a: 30,
                    b: 90
                },
                headers: {
                    name: 'atguigu',
                    age: 20
                },
                data: {
                    name: 'admin',
                    password: 'admin'
                }
            }).then(response => {
                console.log(response)
                console.log(response.data);
            });
        })
    </script>
</body>

</html>